﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace WorldSimulator.PhysicEngine
{
	/// <summary>
	/// Threadsafe CacheItem for physical data
	/// </summary>
	public class MyPhysicsData
	{
		public MyPhysicsData()
		{
		}

		/// <summary>
		/// Lock for the Gravity-Property
		/// </summary>
		private ReaderWriterLockSlim _gravityLock = new ReaderWriterLockSlim();

		/// <summary>
		/// Holds the data for the Gravity-Property
		/// </summary>
		private MyVector3D _gravity = new MyVector3D();

		/// <summary>
		/// Gravity that affects an object
		/// </summary>
		public MyVector3D Gravity
		{
			get
			{
				this._gravityLock.EnterReadLock();
				var gravity = this._gravity;
				this._gravityLock.ExitReadLock();
				return gravity;				
			}

			set
			{
				this._gravityLock.EnterWriteLock();
				this._gravity = value;
				this._gravityLock.ExitWriteLock();
			}
		}

		/// <summary>
		/// Reset all data
		/// </summary>
		public void Reset()
		{
			this.Gravity = new MyVector3D();
		}
	}
}
